﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Diagnostics;
using DW.RtfWriter;
using System.Web.UI.WebControls;

namespace Bussiness.Printing
{
    public class doPrintToRTF
    {

        public doPrintToRTF()
        {

        }


        public void doRTF(Table p_Kalk)
        {
            RtfDocument doc = new RtfDocument(PaperSize.A4, PaperOrientation.Portrait,
               Lcid.English);
            FontDescriptor times = doc.createFont("Times New Roman");
            FontDescriptor courier = doc.createFont("Courier New");
            ColorDescriptor red = doc.createColor(new Color("ff0000"));
            ColorDescriptor blue = doc.createColor(new Color(0, 0, 255));

            RtfTable tbl;


           
            tbl = doc.addTable(p_Kalk.Rows.Count, p_Kalk.Rows[0].Cells.Count);
            tbl.Margins[Direction.Bottom] = 20;
            /// Step 3. (Optional) Set text alignment for each cell, row height, column width,
            ///			border style, etc.
            for (int i = 0; i < tbl.RowCount; i++)
            {
                for (int j = 0; j < tbl.ColCount; j++)
                {
                    tbl.cell(i, j).Alignment = Align.Right;
                    tbl.cell(i, j).AlignmentVertical = AlignVertical.Middle;
                    tbl.cell(i, j).addParagraph().Text = p_Kalk.Rows[i].Cells[j].Text;
                }
            }
            //tbl.setInnerBorder(DW.RtfWriter.BorderStyle.Dotted, 1.5f);
            //tbl.setOuterBorder(DW.RtfWriter.BorderStyle.Double, 3f);
            /// Step 4. Merge cells so that the resulting table would look like the one you drew
            ///			on paper. One cell cannot be merged twice. In this way, we can construct
            ///			almost all kinds of tables we need.
            //tbl.merge(1, 0, 4, 1);
            /// Step 5. You may start inserting content for each cell. Actually, it is adviced
            ///			that the only thing you do after merging cell is inserting content.
   

            doc.save("Demo.rtf");


            /// ==========================================================================
            /// Open the RTF file we just saved
            /// ==========================================================================
            Process p = new Process();
            p.StartInfo.FileName = "Demo.rtf";
            p.Start();

        }
    }
}
